package y2015.date0915pm.客户端;

import org.junit.jupiter.api.Test;
import y2015.date0915pm.服务端.Address;
import y2015.date0915pm.服务端.FactoryPort;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class ChatClient {
    @Test
    public void main() throws Exception {
        Socket socket = null;
        //获取端口号
        FactoryPort factoryPort = new FactoryPort();
        int port = factoryPort.getPortIntance();
        //获取主机ip
        Address address = new Address();
        String host = address.getHost();

        socket = new Socket(host, port);
        System.out.println("客户端已连接");

        //获取服务端数据
        InputStream is = socket.getInputStream();
        BufferedReader read = new BufferedReader(new InputStreamReader(is));
        String readResult = read.readLine();
        System.out.println(readResult);


    }
}

